<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
	<style type="text/css">
		.notice{
			color: red;
		}
	</style>
</head>
<body>
	<form>
		<input type="text" name="username">
		<input type="submit" value="注册">
		<p class="notice"></p>
	</form>
	<script type="text/javascript">
		$(function() {
			$('input[name=username]').blur(function(){
				
				data = $(this).val();
				
				preg = /^[a-z][a-z\d_]{5,7}$/;

				res = preg.test(data);

				if(!res){
					$('.notice').html("用户名有误，要求数字，字母，并且已字母开头6-8")
				}
			})

			$('input[name=username]').focus(function(){
				$('.notice').html('');
			})
		})
	</script>
</body>
</html>